import { Component, ElementRef, ViewChild, AfterViewInit, DoCheck } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit, DoCheck {
  @ViewChild('pageMain') pageMain: ElementRef;
  @ViewChild('appBreadcrumb') appBreadcrumb;

  mainHeight: number;
  hasBreadcrumb = true;

  constructor() {}

  ngAfterViewInit(): void {
    this.mainHeight = this.getMainHeight();

    }

  ngDoCheck(): void {
    this.mainHeight = this.getMainHeight();
    if (this.appBreadcrumb) {
      this.hasBreadcrumb = this.appBreadcrumb.hasBreadcrumb;
    }
  }

  getMainHeight(): number {
    let winH = window.innerHeight,
      mainOffset = this.pageMain.nativeElement.offsetTop,
      mainH = winH - (mainOffset || 0);
    mainH = mainH <= 0 ? 1 : mainH;
    return mainH;
  }
}
